package com.taint.sourcesink;

import java.util.*;

public class MethodHook {
    private String clazzName;
    private String methodName;
    private String type;
    private ArrayList parameters;
    private String returntype;

    public static LinkedHashMap<String, Set<MethodHook>> methodHookMap =new LinkedHashMap<>();

    public static LinkedHashMap<String, Set<MethodHook>> InsertClazz(ArrayList sourcesink, LinkedHashMap<String, Set<MethodHook>> sourcesinkMap) {

        for (Object o : sourcesink) {
            LinkedHashMap single = (LinkedHashMap) o;
            String clazzName = (String) single.get("className");
            String methodName = (String) single.get("method");
            ArrayList parameterList = (ArrayList) single.get("parameters");
            String typeName = (String) single.get("type");
            String returnName = (String) single.get("return");
            //存在key，则已经存在
            if (!sourcesinkMap.containsKey(clazzName)) {
                sourcesinkMap.put(clazzName, new HashSet<>());
            }
            MethodHook methodHook = new MethodHook();
            methodHook.setClazzName(clazzName);
            methodHook.setMethodName(methodName);
            methodHook.setParameters(parameterList);
            methodHook.setType(typeName);
            methodHook.setReturntype(returnName);
            sourcesinkMap.get(clazzName).add(methodHook);
        }
        methodHookMap=sourcesinkMap;
        return sourcesinkMap;
    }


    public String getClazzName() {
        return clazzName;
    }

    public void setClazzName(String clazzName) {
        this.clazzName = clazzName;
    }

    public String getMethodName() {
        return methodName;
    }

    public void setMethodName(String method) {
        this.methodName = method;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }


    public String getReturntype() {
        return returntype;
    }

    public void setReturntype(String returntype) {
        this.returntype = returntype;
    }

    public ArrayList getParameters() {
        return parameters;
    }

    public void setParameters(ArrayList parameters) {
        this.parameters = parameters;
    }


    public static boolean Match(String clazzName,String method){

        return methodHookMap.get(clazzName).contains(method);
    };


}
